import datetime
import sys
# import os


class Logger(object):
    def __init__(self, filename="log.txt"):
        self.terminal = sys.stdout
        self.log = open(filename, "a", encoding="utf-8")

    def write(self, message):
        self.terminal.write(message)
        if message == "\n":
            self.log.write(message)
        else:
            self.log.write(f'{datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")} {message}')
        # self.log.write(f'{message} aaaa')

    def flush(self):
        pass

# path = os.path.abspath(os.path.dirname(__file__))
# type = sys.getfilesystemencoding()
# sys.stdout = Logger()
# print(453453)
# print("abc")
# print("123")